/**
  ******************************************************************************
  * @file    main.c
  * @Author  Simic
  * @version V1.0
  * @date 	 2013-xx-xx
  * @brief   主函数.
  ******************************************************************************
  * @attention
  ******************************************************************************
  */

#include "main.h"
#include "esp8266_init.h"
#include "esp8266_handler.h"

xQueueHandle xQueue_USART2_Cmd;                 /**< 串口2接收消息队列*/

/* 互斥信号量句柄 */
//SemaphoreHandle_t xSemaphore = NULL;


//void Digital_TaskA(void *pvParameters)
//{
//    while(1)
//    {
//        xSemaphoreTake( xSemaphore, portMAX_DELAY );
//        {
//            printf("Task A\r\n");
//        }
//        xSemaphoreGive( xSemaphore );

//        printf("Digital_TaskA\r\n");
//        vTaskDelay( 2000/portTICK_RATE_MS );
//    }
//}

//void Thread_Init_Digital_A(UBaseType_t uxPriority)
//{
//    xTaskCreate( Digital_TaskA, "Digital_TaskA", 256, NULL, uxPriority, NULL );
//}


//void Digital_TaskB(void *pvParameters)
//{
//    uint8_t line_buff[256];
//    signed portBASE_TYPE pd;
//    while(1)
//    {
//        xSemaphoreTake( xSemaphore, portMAX_DELAY );
//        {
//            printf("Task B\r\n");
//        }
//        xSemaphoreGive( xSemaphore );

//        printf("------------\r\n");
//        pd =  xQueueReceive(xQueue_USART2_Cmd, line_buff, portMAX_DELAY);

//        if(pd != pdTRUE)
//        {
//            printf("pd != pdTRUE\r\n");
//            break;
//        }

//		printf("---%s\r\n",line_buff);
//		memset(line_buff,0,sizeof(line_buff));

//        vTaskDelay( 10/portTICK_RATE_MS );
//    }
//}

//void Thread_Init_Digital_B(UBaseType_t uxPriority)
//{
//    xTaskCreate( Digital_TaskB, "Digital_TaskB", 256, NULL, uxPriority, NULL );
//}

void vCollectSensorTask(void *ptr)
{
    while (1)
    {
        SHT20_GetValue();
//		debug_logI("temperature:%.1f,humilty:%.1f",sht20Info.tempreture,sht20Info.humidity);
        /*向看门狗喂狗*/
//        xEventGroupSetBits(xCreatedEventGroup, TASK_BIT_1);
        vTaskDelay(500 / portTICK_RATE_MS);
    }
}

/**
  * @brief  主函数
  * @param  无
  * @retval 无
  */
int main ( void )
{
    /** 设备初始化 */
    BSP_Init();
	esp8266_init();
    /* 创建互斥信号量 */
//    xSemaphore = xSemaphoreCreateMutex();

    /* 创建串口接收消息队列 */
	xQueue_USART2_Cmd = xQueueCreate(1, 128);

//    Thread_Init_Digital_A(USER_THREAD_PRIORITY_4);
//    Thread_Init_Digital_B(USER_THREAD_PRIORITY_3);  vEsp8266_Main_Task

	
	xTaskCreate( vGetEsp8266Status,   	"vGetEsp8266Status",  	256, NULL, configMAX_PRIORITIES - 3, NULL);
	xTaskCreate( vAnalysisUartData,   	"vAnalysisUartData",  	256, NULL, configMAX_PRIORITIES - 2, NULL);	
	xTaskCreate( vEsp8266_Main_Task,   	"vEsp8266_Main_Task",  	128, NULL, configMAX_PRIORITIES - 4, NULL);
	xTaskCreate( vCollectSensorTask,   	"vCollectSensorTask",  	128, NULL, configMAX_PRIORITIES - 4, NULL);
    /** 启动调度，开始执行任务 */
    vTaskStartScheduler();
}

/*********************************************END OF FILE**********************/


